package com.xmb.common.service.wx.strategy;

import com.xmb.common.constants.PayEnum;
import com.xmb.common.entity.structure.PayOrderInfo;
import com.xmb.common.exception.BusinessException;
import com.xmb.common.params.WxPayUnifiedOrdeParam;
import com.xmb.common.remote.entity.ProductOrder;
import com.xmb.common.remote.service.ShopService;
import com.xmb.common.service.impl.GetPayOrderStrategy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by lyndon on 2019/3/27.
 */
@Component
public class ShopOrderStrategy extends GetPayOrderStrategy {

    @Override
    public String getType() {
        return PayEnum.shop.name();
    }

    @Resource
    private ShopService shopService;

    @Override
    public PayOrderInfo process(WxPayUnifiedOrdeParam payParam) {

        ProductOrder productOrder = shopService.getProductOrderOne(payParam.getOrderId());
        if (productOrder == null) {
            throw new BusinessException("无法获取到需要支付的订单信息");
        }
        PayOrderInfo orderInfo = new PayOrderInfo();
        orderInfo.setBody(productOrder.getProductNo());
        orderInfo.setOrderAmount(productOrder.getRealPayment());
        orderInfo.setPayPrefix(payParam.getOrderType());
        orderInfo.setOrderId(productOrder.getId());
        return orderInfo;
    }

}
